import React, { Component } from "react";
const btnRef = React.createRef();
export default class App extends Component {
  state = {
    msg: "hello kitty",
  };
  changeHandler = () => {
    this.setState({
      msg: "hello react",
    });
    console.log(this.state.msg);
  };
  componentDidMount() {
    // console.log(btnRef.current);
    // btnRef.current.onclick = () => {
    //   this.setState({
    //     msg: "hello react",
    //   });
    //   console.log(this.state.msg);
    // };

    setTimeout(() => {
      this.setState({
        msg: "hello react",
      });
      console.log(this.state.msg);
    }, 2000);
  }
  render() {
    let { msg } = this.state;
    return (
      <div>
        <h2>{msg}</h2>
        <button ref={btnRef}>点我</button>
      </div>
    );
  }
}
